﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class TotalPlan_PopTotalPlanAdd : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {

            BindDropDownList();
        }
    }

    /// <summary>
    /// 绑定下来列表
    /// </summary>
    void BindDropDownList()
    {
        DepartmentInfoManager dllDepartmentInfoManager = new DepartmentInfoManager();
        DataTable dt = dllDepartmentInfoManager.getNoTree();
        this.drpDepartment.DataSource = dt;
        this.drpDepartment.DataTextField = "DepartmentName";
        this.drpDepartment.DataValueField = "DepartmentId";
        this.drpDepartment.DataBind();
        object[] _value = new object[1];
        Model.UserInfo objUserInfo = new Model.UserInfo();
        _value[0] = objUserInfo.UserName;
        UserInfoManager dllUserInfoManager = new UserInfoManager();
        DataTable _userTable = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _value);
        if (_userTable.Rows.Count > 0)
        {
            this.drpDepartment.SelectedIndex = this.drpDepartment.Items.IndexOf(this.drpDepartment.Items.FindByText(_userTable.Rows[0]["DepartmentId"].ToString()));
        }
    }


    /// <summary>
    /// 添加总表计划事件 状态为2，提交状态
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        TotalPlanMgr dllTotalPlanMgr = new TotalPlanMgr();
        object[] _value = new object[9];
        //序号
        _value[0] = this.txtStrategicPlanSortId.Text;
        //结束时间
        _value[1] = Convert.ToDateTime(this.txtEndDay.Text);
        //计划内容
        _value[2] = this.txtPlanContent.Text;
        //负责部门
        _value[3] = this.drpDepartment.SelectedItem.Text;
        //负责人
        _value[4] = this.txtMasterPeople.Value;
        //年份
        _value[5] = Utility.HttpHelp.getParamsString("TotalYear");
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        DataTable _VerifyCircuitId = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_VerifyCircuitId.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
            return;
        }
        else
        {
            //审核流程id
            _value[6] = Convert.ToInt32(_VerifyCircuitId.Rows[0]["VerifyCircuitId"].ToString());
        }
        //计划状态
        _value[7] = 2;
        _value[8] = objUserInfo.UserName;
        int result = dllTotalPlanMgr.addForAdmin(_value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("添加总表计划未成功，请重试！");
        }
        else
        {
            string _url = Utility.HttpHelp.getParamsString("Url");
            _url += "?TotalYear=" + Utility.HttpHelp.getParamsString("TotalYear");
            Utility.HttpHelp.closeWindow(_url, Page);
        }
    }
}
